import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { isTenantRoleLevel } from 'utils/utils'; // 国家定义角色层级判断

function countryApi(params) {
  return isTenantRoleLevel() ? "".concat(params.tenantId, "/countries") : 'countries';
}
/**
 * 查询国家定义列表的数据
 * @param {Object} params - 查询参数
 * @param {String} params.page - 页码
 * @param {String} params.size - 页数
 */


export function fetchCountryList(_x) {
  return _fetchCountryList.apply(this, arguments);
}
/**
 * 新增国家
 * @param {Object} params - 查询参数
 * @param {String} params.todoContent - todoItem 的内容
 * @param {String} params.status - todoItem 的状态
 */

function _fetchCountryList() {
  _fetchCountryList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(countryApi(params)), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchCountryList.apply(this, arguments);
}

export function createCountry(_x2) {
  return _createCountry.apply(this, arguments);
}
/**
 * 更新国家数据
 * @param {Object} params - 查询参数
 * @param {String} params.page - 页码
 * @param {String} params.size - 页数
 */

function _createCountry() {
  _createCountry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(isTenantRoleLevel() ? "".concat(params.tenantId, "/country") : 'country'), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _createCountry.apply(this, arguments);
}

export function updateCountry(_x3) {
  return _updateCountry.apply(this, arguments);
}
/**
 * 删除国家定义行数据
 * @param {Object} params - 参数
 * @param {String} params.todoContent - todoItem 的内容
 * @param {String} params.status - todoItem 的状态
 */

function _updateCountry() {
  _updateCountry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(countryApi(params), "/").concat(params.countryId), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _updateCountry.apply(this, arguments);
}

export function deleteCountry(_x4) {
  return _deleteCountry.apply(this, arguments);
}

function _deleteCountry() {
  _deleteCountry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(countryApi(params)), {
              method: 'DELETE',
              body: params.seleCountryRows
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _deleteCountry.apply(this, arguments);
}